package com.polaris.live.ui.main.fragment

import android.os.Bundle
import androidx.core.os.bundleOf
import com.polaris.live.common.adapter.ViewPagerAdapter
import com.polaris.live.common.mvvm.base2.BaseVbFragment
import com.polaris.live.constant.UserRankConst
import com.polaris.live.databinding.FragmentUserListBinding
import com.polaris.live.viewmodel.login.UserRankViewModel

/**
 * 财富榜
 *
 * @author Created by lucas on 2023/10/30 17:21
 * @since 1.0.0
 */
class WealthFragment : BaseVbFragment<UserRankViewModel, FragmentUserListBinding>() {

    private var onChange: ((Int) -> Unit)? = null

    private val mRankType by lazy { arguments?.getInt("rankType", UserRankConst.RANK_DAY) }

    override fun initView(savedInstanceState: Bundle?) {
        val dailyListFragment = DailyListFragment().apply {
            arguments = bundleOf(
                "type" to UserRankConst.TYPE_RICH
            )
        }
        val monthListFragment = MonthListFragment().apply {
            arguments = bundleOf(
                "type" to UserRankConst.TYPE_RICH
            )
        }

        mBinding.vpList.adapter =
            ViewPagerAdapter(mutableListOf(dailyListFragment, monthListFragment), this)
        mBinding.rgRank.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                mBinding.rbDailyList.id -> {
                    mBinding.vpList.setCurrentItem(0, true)
                    onChange?.invoke(0)
                }
                mBinding.rbMonthlyList.id -> {
                    mBinding.vpList.setCurrentItem(1, true)
                    onChange?.invoke(1)
                }
            }
        }
        if (mRankType == UserRankConst.RANK_MOTH) {
            mBinding.rbMonthlyList.isChecked = true
        }
    }

    fun setOnChange(onChange: ((Int) -> Unit)) {
        this.onChange = onChange
    }
}